package edu.sjb_beta1;

import edu.sjb_beta1.gui.GUI;
import edu.sjb_beta1.tools.ExtensionFilter;
import java.io.File;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;

public class AppLauncher {
    /**
     * @param args
     */
    public static void main(String[] args) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info :
                    javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        }
        catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(GUI.class.getName()).log(
                    java.util.logging.Level.SEVERE, null, ex);
        }
        catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(GUI.class.getName()).log(
                    java.util.logging.Level.SEVERE, null, ex);
        }
        catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(GUI.class.getName()).log(
                    java.util.logging.Level.SEVERE, null, ex);
        }
        catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(GUI.class.getName()).log(
                    java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        JFileChooser fc = new JFileChooser("./levels/");
        ExtensionFilter ef = new ExtensionFilter("Super JAVA Bros level (*.sjl)",
                ".sjl");
        fc.addChoosableFileFilter(ef);
        fc.setFileFilter(ef);
        int result = fc.showOpenDialog(null);
        if (result == JFileChooser.APPROVE_OPTION) {
            File chosen = fc.getSelectedFile();
            /* Create and display the form */
            GUI gameGUI = new GUI(chosen);
            gameGUI.setVisible(true);
        }
        else {
            JOptionPane.showMessageDialog(null,
                    "File opening cancelled by user. Super Java Bros will exit.",
                    "Level loading cancelled",
                    JOptionPane.INFORMATION_MESSAGE);
        }
    }
}